package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.PingjiaDetailBean;
import com.lwj.liwanjia.utils.CircleTransform;
import com.lwj.liwanjia.utils.MultiImageViewLayout;
import com.lwj.liwanjia.utils.RatingBar;
import com.superrecycleview.superlibrary.adapter.BaseViewHolder;
import com.superrecycleview.superlibrary.adapter.SuperBaseAdapter;

import java.util.List;

/**
 * 客户评价
 */

public class DetailPingjiaAdapter extends SuperBaseAdapter<PingjiaDetailBean.DataBean> {
    private Context mContext;

    public DetailPingjiaAdapter(Context context, List<PingjiaDetailBean.DataBean> data) {
        super(context, data);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder holder, PingjiaDetailBean.DataBean item, int position) {
        Glide.with(mContext).load(item.getHeadImg()).placeholder(R.mipmap.headportrait).transform(new CircleTransform(mContext)).error(R.mipmap.headportrait).into((ImageView) holder.getView(R.id.kehu_touxiang));
        RatingBar ratingBar = holder.getView(R.id.rating_bar);
        ratingBar.setStar(item.getCommentGrade());
        MultiImageViewLayout multiImageView = holder.getView(R.id.pingjia_image);
        if (item.getImgs() != null && item.getImgs().size() > 0) {
            multiImageView.setList(item.getImgs());
        }
        holder.setText(R.id.kehu_name, item.getUserNick())
                .setText(R.id.kehu_pingjia_time, item.getCommentTime())
                .setText(R.id.pingjia_content, item.getCommentContent());

        if(TextUtils.isEmpty(item.getAddCommentContent())){
            holder.setVisible(R.id.zhuijia_pingjia,false);
        }else{
            holder.setVisible(R.id.zhuijia_pingjia, true)
                    .setText(R.id.zhuijia_content, item.getAddCommentContent());
        }

        if (TextUtils.isEmpty(item.getReplyTime())) {
            holder.setVisible(R.id.shangjia_huifu, false);
        } else {
            holder.setVisible(R.id.shangjia_huifu, true)
                    .setText(R.id.shangjia_huifu_time, item.getReplyTime())
                    .setText(R.id.shangjia_huifu_content, item.getReplyInfo());
        }
    }

    @Override
    protected int getItemViewLayoutId(int position, PingjiaDetailBean.DataBean item) {
        return R.layout.pingjiadetail_item;
    }
}
